import Vue from 'vue'
import Router from 'vue-router'
import Login from '../page/login/login'
import Common from '../components/common'
import homepage from '../page/homepage/index' //首页
import Addgoods from '../page/commercial/addgoodes' //添加商品
import Goodmanage from '../page/commercial/goodmanage' //商品管理
import dome from '../page/commercial/dome' //
import Seegoods from '../page/commercial/seegoods' //查看
import Ordermange from '../page/shoppOrder/ordermange' //订单管理
import Orderdetails from '../page/shoppOrder/orderdetails' //订单详情
import FreeAddgoods from '../page/freemange/freeAddgoods' //自由市场添加商品
import FreegoodsMange from '../page/freemange/freegoodsMange' //自由市场商品管理
import Print from '../page/freemange/print' //ID打印
import Storage from '../page/stockControl/storage' //库存管理--入库
import storageDetail from '../page/stockControl/storageDetail' //库存管理--入库明细
import storeManagement from '../page/stockControl/storeManagement' //库存管理--仓库管理
import detail from '../page/stockControl/detail' //库存管理--货位管理

import freeMarket from '../page/transaction/freeMarket' //交易管理--自由市场
import holding from '../page/transaction/holding' //交易管理--持有管理
import delegateList from '../page/transaction/delegateList' //交易管理--委托列表
import transaction from '../page/transaction/transaction' //交易管理--交易明细

import accountBalance from '../page/fundManage/accountBalance' //资金管理--账号余额
import accountManage from '../page/fundManage/accountManage' //资金管理--子账号管理
import subAccountBalance from '../page/fundManage/subAccountBalance' //资金管理--子账号余额
import capitalDetails from '../page/fundManage/capitalDetails' //资金管理--资金明细
import bankCard from '../page/fundManage/bankCard' //资金管理--银行卡管理
import autoDelegate from '../page/autoDelegation/autoDelegate' //委托管理

import account from '../page/systemManage/account' 
import roleManage from '../page/systemManage/roleManage' 
import automaticList from '../page/transaction/automaticList' 
Vue.use(Router)

const router = new Router({
    routes: [
        {
          path: '/login',
          name: '登录',
          component: Login,
          meta: {
            title: '用户登录'
          }
        },
        {
            path:'/',
            component: Common,
           
            children:[
                {
                    path: '/',
                    name: '首页',
                    component: homepage,
                    meta: {
                      title: '首页'
                    }  
                },
                {
                  path: '/account',
                  name: '帐号管理',
                  component: account,
                  meta: {
                    title: '系统管理'
                  }  
              },
              {
                  path: '/roleManage',
                  name: '角色管理',
                  component: roleManage,
                  meta: {
                    title: '系统管理'
                  }  
              },
                {
                    path: '/addgoods',
                    name: '添加商品',
                    component: Addgoods,
                    meta: {
                      title: '商城商品管理'
                    }  
                },
                {
                    path: '/goodmanage',
                    name: '商品管理',
                    component: Goodmanage,
                    meta: {
                      title: '商城商品管理'
                    }  
                },
                {
                    path: '/seegoods',
                    name: '查看商品',
                    component: Seegoods,
                    meta: {
                      title: '商城商品管理'
                    }  
                },
                {
                    path: '/ordermange',
                    name: '订单管理',
                    component: Ordermange,
                    meta: {
                      title: '商城订单管理'
                    }  
                },
                {
                    path: '/orderdetails',
                    name: '订单管理详情',
                    component: Orderdetails,
                    meta: {
                      title: '商城订单管理'
                    }  
                },
                {
                    path: '/freeaddgoods',
                    name: '自由市场添加商品',
                    component: FreeAddgoods,
                    meta: {
                      title: '自由市场商品管理'
                    }  
                },
                {
                    path: '/freegoodsMange',
                    name: '自由市场商品管理',
                    component: FreegoodsMange,
                    meta: {
                      title: '自由市场商品管理'
                    }  
                },
                {
                    path: '/rrint',
                    name: '商品打印',
                    component: Print,
                    meta: {
                      title: '自由市场商品管理'
                    }  
                },
                {
                    path: '/storage',
                    name: '入库',
                    component: Storage,
                    meta: {
                      title: '库存管理'
                    }  
                },
                {
                    path: '/storeManagement',
                    name: '仓库管理',
                    component: storeManagement,
                    meta: {
                      title: '库存管理'
                    }  
                },
                {
                  path: '/detail',
                  name: '货位管理',
                  component: detail,
                  meta: {
                    title: '库存管理'
                  }  
                },
                {
                    path: '/storageDetail',
                    name: '入库明细',
                    component: storageDetail,
                    meta: {
                      title: '库存管理'
                    }  
                },
                {
                    path: '/freeMarket',
                    name: '自由市场',
                    component: freeMarket,
                    meta: {
                      title: '交易管理'
                    }  
                },
                {
                    path: '/holding',
                    name: '持有管理',
                    component: holding,
                    meta: {
                      title: '交易管理'
                    }  
                },
                {
                    path: '/delegateList',
                    name: '委托列表',
                    component: delegateList,
                    meta: {
                      title: '交易管理'
                    }  
                },
                {
                    path: '/transaction',
                    name: '交易明细',
                    component: transaction,
                    meta: {
                      title: '交易管理'
                    }  
                },
                {
                    path: '/accountBalance',
                    name: '账户余额',
                    component: accountBalance,
                    meta: {
                      title: '资金管理'
                    }  
                },
                {
                    path: '/accountManage',
                    name: '子账户管理',
                    component: accountManage,
                    meta: {
                      title: '资金管理'
                    }  
                },
                {
                    path: '/subAccountBalance',
                    name: '子账户余额',
                    component: subAccountBalance,
                    meta: {
                      title: '资金管理'
                    }  
                },
                {
                    path: '/capitalDetails',
                    name: '资金明细',
                    component: capitalDetails,
                    meta: {
                      title: '资金管理'
                    }  
                },
                {
                    path: '/bankCard',
                    name: '银行卡管理',
                    component: bankCard,
                    meta: {
                      title: '资金管理'
                    }  
                },
                {
                  path: '/dome',
                  name: 'dome',
                  component: dome,
                  meta: {
                    title: 'dome'
                  }  
              },
              {
                path: '/autoDelegate',
                name: '自动委托',
                component: autoDelegate,
                meta: {
                  title: '交易管理'
                }  
              },
              {
                path: '/automaticList',
                name: '开盘挂单',
                component: automaticList,
                meta: {
                  title: '交易管理'
                }  
              }
            ]

        }
    ]
})
router.beforeEach((to, from, next) => {
    document.title = to.name;
    if (to.query.token) {
      localStorage.setItem('timetoken', to.query.token);
    }
    if (localStorage.getItem('timetoken')) {
      if (to.path == "/login") {
        next('/')
      } else {
        next();
      }
    } else {
      if (to.path == "/login") {
        next();
      } else {
        next('/login');
      }
    }
  });
export default router